<template>
	<view class="">
		<u-navbar :is-back="true" title="编辑信息" back-icon-color="#ffffff" :background="{backgroundColor:'#E62131'}"
			title-color="#ffffff"></u-navbar>
		<view class="" style="padding: 0 30rpx;">
			<u-form :model="form" ref="uForm">
				<u-form-item label="姓名"><u-input v-model="form.name" /></u-form-item>
				<u-form-item label="电话"><u-input v-model="form.phone" /></u-form-item>

				<u-form-item label="性别"><u-input v-model="textsa" type="select" @click="show= true" /></u-form-item>
				<u-form-item label="备注"><u-input v-model="form.remarks" /></u-form-item>
				<u-form-item label="头像">
					<view class="" style="width: 100%; display: flex;align-items: center;justify-content: flex-end;">
						<u-image width="90rpx" height="90rpx" :src="form.headImg"
								shape="circle"  @click="tomedetss"></u-image>
					</view>
				</u-form-item>
			</u-form>
			<u-action-sheet :list="actionSheetList" v-model="show" @click="actionSheetCallback"></u-action-sheet>
		</view>
		<view class="bneads w-btn-fixed">
			<div class="btnlst fliexs space_between">
				<view class="btn_left right" @click="okllists">
					确定
				</view>
			</div>
		
		</view>
	</view>
</template>

<script>
	import staticUrl from "@/common/config.js"
	export default {
		data() {
			return {
				action: staticUrl.staticUrl,
				header: {
					accessToken: 'bearer ' + uni.$func.cache("token"),
				},
				form: {
					name: '',
					phone: '',
					remarks: '',
					headImg: '',
					sex: 0,
					id:'',
				},
				show: false,
				textsa: "男",
				actionSheetList: [{
						text: '男',
						value: 0
					},
					{
						text: '女',
						value: 1
					},
				],
				radio: '',
				switchVal: false,
				studentId:null,
			};
		},
		onLoad(option) {
			this.form.id = option.studentId
			this.iflsoList()
		},
		methods: {
			okllists(){
				uni.$api.common.editStudentInfo(this.form).then((res) => {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
					setTimeout(() => {
						uni.navigateBack({
							delta: 1,
						})
					}, 2000)
					
				});
			},
			iflsoList(){
				uni.$api.common.getStudentInfoById(this.form.id).then((res) => {
					let obgs =  res.result.studentInfo
					this.form.name = obgs.name
					this.form.phone = obgs.phone
					this.form.remarks = obgs.remarks
					this.form.headImg = obgs.headImg
					this.form.sex = obgs.sex
					
				});
			},
			// 点击actionSheet回调
			actionSheetCallback(index) {
				this.textsa = this.actionSheetList[index].text
				this.form.sex = this.actionSheetList[index].value
			},
			tomedetss() {
				// 项目实战中使用
				let _this = this;
				uni.chooseImage({
					count: 1, // 图片数量
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album', 'camera'], //从相册选择或者拍照
					success: (res) => {
						const tempFilePaths = res.tempFilePaths;
						console.log(tempFilePaths[0])
						_this.logo_list = tempFilePaths[0]
						uni.uploadFile({
							url: _this.action, //上传图片api
							filePath: tempFilePaths[0],
							header: _this.header,
							success: (res) => {
								uni.showToast({
									title: "上传成功",
									icon: "success"
								})
								let obgs = JSON.parse(res.data)
								this.form.headImg = obgs.result.path
							}
						});
					}
				});
			}
		}
	};
</script>

<style lang="scss">
	.btnlst {
		// margin-top: 350rpx;
	
		.btn_left {
			width: 100%;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			color: #b1b1b1;
			border: 1rpx solid #e1e1e1;
		}
	
		.right {
			background-color: #E62131;
			color: #ffffff;
		}
	}
</style>